from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship

from src.models.base import TimeModel


class User(TimeModel):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    email = Column(String(255), unique=True, nullable=True, comment='用户绑定邮箱')
    username = Column(String(64), unique=True, comment='gitcode登录用户名')
    gitcode_name = Column(String(64), comment='gitcode昵称')
    gitcode_id = Column(String(32), unique=True, comment='gitcode用户唯一id（uuid）')

    repositories = relationship('Repository', back_populates='owner')
    issues = relationship('Issue', back_populates='author')
    pull_requests = relationship('PullRequest', back_populates='author')
    advices = relationship('Advice', back_populates='author')

    def __str__(self):
        return self.username


class Company(TimeModel):
    __tablename__ = 'company'

    id = Column(Integer, primary_key=True)
    name = Column(String(128), unique=True, comment='公司名')

    def __str__(self):
        return self.name